package com.pomr.model.equipmentstorage;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Formula;
import org.hibernate.annotations.GenericGenerator;

import com.pomr.model.synthesize.Equipment;
import com.pomr.model.synthesize.Manufacturer;
import com.pomr.model.sys.Agency;

/**
 * 设备库存主表
 * @author Administrator
 *
 */
@Entity
@Table(name="equipment_storage",uniqueConstraints = {@UniqueConstraint(columnNames={"equipment_id","manufacturer_id","agency_id"})})
public class EquipmentStorage implements Serializable{
	
	public String getEspecification() {
		return especification;
	}

	public void setEspecification(String especification) {
		this.especification = especification;
	}

	public double getEarnestmoney() {
		return earnestmoney;
	}

	public void setEarnestmoney(double earnestmoney) {
		this.earnestmoney = earnestmoney;
	}

	public String getEquipmentName() {
		return equipmentName;
	}

	public void setEquipmentName(String equipmentName) {
		this.equipmentName = equipmentName;
	}

	public String getManufacturerName() {
		return manufacturerName;
	}

	public void setManufacturerName(String manufacturerName) {
		this.manufacturerName = manufacturerName;
	}

	public String getAgencyName() {
		return agencyName;
	}

	public void setAgencyName(String agencyName) {
		this.agencyName = agencyName;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Equipment getEquipment() {
		return equipment;
	}

	public void setEquipment(Equipment equipment) {
		this.equipment = equipment;
	}

	public Manufacturer getManufacturer() {
		return manufacturer;
	}

	public void setManufacturer(Manufacturer manufacturer) {
		this.manufacturer = manufacturer;
	}

	public Agency getAgency() {
		return agency;
	}

	public void setAgency(Agency agency) {
		this.agency = agency;
	}

	public Integer getStockNumber() {
		return stockNumber;
	}

	public void setStockNumber(Integer stockNumber) {
		this.stockNumber = stockNumber;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "native")
    @GenericGenerator(name = "native", strategy = "native")//AUTO 在mysql中需要指定使用本地策略生成主键值
	private Integer id;//主键
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="equipment_id")
	private Equipment equipment;//设备主键
	
	@Formula("(select me.name from menu_equipment me where me.id=( select e.kind_id from equipment e where e.id=equipment_id))")
	private String equipmentName;//设备名称
	
	@Formula("(select e1.specification from equipment e1 where e1.id=equipment_id)")
	private String especification;//设备型号
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="manufacturer_id")
	private Manufacturer manufacturer;//厂商主键
	
	@Formula("(select m.name from manufacturer m where m.id=manufacturer_id)")
	private String manufacturerName;//厂商名称
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="agency_id")
	private Agency agency;//机构主键
	
	@Formula("(select a.name from agency a where a.id=agency_id)")
	private String agencyName;//机构名称
	
	@Column(name="stock_number")
	private Integer stockNumber;//库存数
	
	@Column(name="earnestmoney",columnDefinition="double(10,2) default '0.00'")
	private double earnestmoney;//领取定金

}
